package com.tianyang.yukuaifuzs.business.main.provider;

import android.content.Context;
import android.content.Intent;

import com.alibaba.fastjson.JSON;
import com.tianyang.yukuaifuzs.business.login.view.PrivacyBrowserActivity;
import com.tianyang.yukuaifuzs.business.main.bean.BrowserInput;
import com.tianyang.yukuaifuzs.business.main.bean.PosUserOutput;
import com.tianyang.yukuaifuzs.business.main.contract.MainConfig;
import com.tianyang.yukuaifuzs.business.main.view.BindCodePlateActivity;
import com.tianyang.yukuaifuzs.business.main.view.BrowserX5Activity;
import com.tianyang.yukuaifuzs.business.main.view.CaptureActivity;
import com.tianyang.yukuaifuzs.business.main.view.ChooseSoundActivity;
import com.tianyang.yukuaifuzs.business.main.view.CodePlateListActivity;
import com.tianyang.yukuaifuzs.business.main.view.DeviceListActivity;
import com.tianyang.yukuaifuzs.business.main.view.HelpCenterActivity;
import com.tianyang.yukuaifuzs.business.main.view.InviteCodeActivity;
import com.tianyang.yukuaifuzs.business.main.view.MerchantDetailActivity;
import com.tianyang.yukuaifuzs.business.main.view.MerchantInfoAuthActivity;
import com.tianyang.yukuaifuzs.business.main.view.MerchantManageActivity;
import com.tianyang.yukuaifuzs.business.main.view.ModifyDeviceActivity;
import com.tianyang.yukuaifuzs.business.main.view.MyCodePlateActivity;
import com.tianyang.yukuaifuzs.business.main.view.PermissionSettingActivity;
import com.tianyang.yukuaifuzs.business.main.view.RateConfigsActivity;
import com.tianyang.yukuaifuzs.business.main.view.ServiceManageActivity;
import com.tianyang.yukuaifuzs.business.main.view.ServiceRegisterActivity;
import com.tianyang.yukuaifuzs.business.main.view.SettingCenterActivity;
import com.tianyang.yukuaifuzs.business.main.view.SettleManageActivity;
import com.tianyang.yukuaifuzs.business.main.view.StoreManageActivity;
import com.tianyang.yukuaifuzs.business.trade.view.ServicePlatformActivity;
import com.tianyang.yukuaifuzs.utils.IntentTool;

import java.util.Map;

/**
 * Description：Main模块内部跳转类
 */

public class MainOpenProvider {

    private static MainOpenProvider instance;

    public static MainOpenProvider getInstance() {
        if (instance == null) {
            synchronized (MainOpenProvider.class) {
                if (instance == null) {
                    instance = new MainOpenProvider();
                }
            }
        }
        return instance;
    }

    /**
     * 设置中心
     */
    public void openSettingCenterActivity(Context context) {
        IntentTool.startActivity(context, SettingCenterActivity.class);
    }

    /**
     * 系统权限
     */
    public void openPermissionSettingActivity(Context context) {
        IntentTool.startActivity(context, PermissionSettingActivity.class);
    }

    /**
     * 邀请
     */
    public void openInviteCodeActivity(Context context) {
        IntentTool.startActivity(context, InviteCodeActivity.class);
    }

    /**
     * 商户管理
     */
    public void openMerchantManageActivity(Context context) {
        IntentTool.startActivity(context, MerchantManageActivity.class);
    }

    /**
     * 商户详情
     */
    public void openMerchantDetailActivity(Context context, PosUserOutput output) {
        Intent intent = new Intent(context, MerchantDetailActivity.class);
        intent.putExtra(MainConfig.INTENT_POS_USER_OUTPUT, output);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 商户详情
     */
    public void openMerchantInfoAuthActivity(Context context, PosUserOutput output, boolean isWx) {
        Intent intent = new Intent(context, MerchantInfoAuthActivity.class);
        intent.putExtra(MainConfig.INTENT_POS_USER_OUTPUT, output);
        intent.putExtra(MainConfig.INTENT_IS_WX, isWx);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 服务商管理
     */
    public void openServiceManageActivity(Context context) {
        IntentTool.startActivity(context, ServiceManageActivity.class);
    }

    /**
     * 服务商信息
     */
    public void openServiceRegisterActivity(Context context) {
        IntentTool.startActivity(context, ServiceRegisterActivity.class);
    }

    /**
     * 费率配置
     * isAgent 0:商户， 1代理商
     */
    public void openRateConfigActivity(Context context, String userName, int isAgent, boolean isRateConfig) {
        Intent intent = new Intent(context, RateConfigsActivity.class);
        intent.putExtra(MainConfig.INTENT_USER_NAME, userName);
        intent.putExtra(MainConfig.INTENT_IS_AGENT, isAgent);
        intent.putExtra(MainConfig.INTENT_IS_RATE_CONFIG, isRateConfig);
        IntentTool.startActivity(context, intent);
    }

    public void openRateConfigActivity(Context context, String userName, int isAgent, boolean isRateConfig,
                                       String posChannel, Map<String, String> params) {
        Intent intent = new Intent(context, RateConfigsActivity.class);
        intent.putExtra(MainConfig.INTENT_USER_NAME, userName);
        intent.putExtra(MainConfig.INTENT_IS_AGENT, isAgent);
        intent.putExtra(MainConfig.INTENT_IS_RATE_CONFIG, isRateConfig);
        intent.putExtra(MainConfig.INTENT_POS_CHANNEL, posChannel);
        intent.putExtra(MainConfig.INTENT_PARAMS, JSON.toJSONString(params));
        IntentTool.startActivity(context, intent);
    }

    /**
     * 码牌/音响列表
     */
    public void openCodePlateListActivity(Context context, String deviceType, String title, String userId) {
        Intent intent = new Intent(context, CodePlateListActivity.class);
        intent.putExtra(MainConfig.INTENT_DEVICE_TYPE, deviceType);
        intent.putExtra(MainConfig.INTENT_TITLE, title);
        intent.putExtra(MainConfig.INTENT_USER_ID, userId);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 我的码牌
     */
    public void openMyCodePlateActivity(Context context, String imageUrl, String title, String userId) {
        Intent intent = new Intent(context, MyCodePlateActivity.class);
        intent.putExtra(MainConfig.INTENT_IMAGE_URL, imageUrl);
        intent.putExtra(MainConfig.INTENT_TITLE, title);
        intent.putExtra(MainConfig.INTENT_USER_ID, userId);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 绑定码牌
     */
    public void openBindCodePlateActivity(Context context, String deviceType, String title, String userId) {
        Intent intent = new Intent(context, BindCodePlateActivity.class);
        intent.putExtra(MainConfig.INTENT_DEVICE_TYPE, deviceType);
        intent.putExtra(MainConfig.INTENT_TITLE, title);
        intent.putExtra(MainConfig.INTENT_USER_ID, userId);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 修改设备名称
     */
    public void openModifyDeviceActivity(Context context, String deviceId, String deviceName, String userId) {
        Intent intent = new Intent(context, ModifyDeviceActivity.class);
        intent.putExtra(MainConfig.INTENT_DEVICE_ID, deviceId);
        intent.putExtra(MainConfig.INTENT_DEVICE_NAME, deviceName);
        intent.putExtra(MainConfig.INTENT_USER_ID, userId);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 选择音响
     */
    public void openChooseSoundActivity(Context context, int requestCode, String userId) {
        Intent intent = new Intent(context, ChooseSoundActivity.class);
        intent.putExtra(MainConfig.INTENT_USER_ID, userId);
        IntentTool.startActivityForResult(context, intent, requestCode);
    }

    /**
     * 扫一扫
     */
    public void openCaptureActivity(Context context, int requestCode) {
        IntentTool.startActivityForResult(context, CaptureActivity.class, requestCode);
    }

    /**
     * 帮助中心
     */
    public void openHelpCenterActivity(Context context) {
        IntentTool.startActivity(context, HelpCenterActivity.class);
    }

    /**
     * 店铺门店管理
     */
    public void openStoreManageActivity(Context context) {
        IntentTool.startActivity(context, StoreManageActivity.class);
    }

    /**
     * 服务商平台
     */
    public void openServicePlatformActivity(Context context) {
        IntentTool.startActivity(context, ServicePlatformActivity.class);
    }

    /**
     * 设备列表
     */
    public void openDeviceListActivity(Context context) {
        IntentTool.startActivity(context, DeviceListActivity.class);
    }

    public void openDeviceListActivity(Context context, String userId) {
        Intent intent = new Intent(context, DeviceListActivity.class);
        intent.putExtra(MainConfig.INTENT_USER_ID, userId);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 结算管理
     */
    public void openSettleManageActivity(Context context) {
        IntentTool.startActivity(context, SettleManageActivity.class);
    }

    /**
     * 浏览器
     *
     * @param context     上下文
     * @param title       标题，如不传就用webview的标题
     * @param url         访问地址
     * @param referrer    签名头
     * @param content     html串（url为空时）
     * @param showTitle   是否显示标题   true 显示 false 不显示
     * @param showPreLoad 是否显示加载框 true 显示 false 不显示
     */
    public void openBrowserX5Activity(Context context, String title, String url, String referrer,
                                      String content, boolean showTitle, boolean showPreLoad) {
        BrowserInput input = new BrowserInput();
        input.setTitle(title);
        input.setUrl(url);
        input.setReferrer(referrer);
        input.setContent(content);
        input.setShowTitle(showTitle);
        input.setShowPreLoad(showPreLoad);
        Intent intent = new Intent();
        intent.setClass(context, BrowserX5Activity.class);
        intent.putExtra(MainConfig.INTENT_BROWSER_INPUT, input);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 传入html串访问浏览器
     * 显示标题栏，不显示加载框
     */
    public void openBrowserX5Activity(Context context, String content) {
        openBrowserX5Activity(context, null, null, null, content, true, false);
    }

    /**
     * 传入url串访问浏览器
     * 显示标题栏，显示加载框
     */
    public void openBrowserX5Activity(Context context, String title, String url) {
        openBrowserX5Activity(context, title, url, null, null, true, true);
    }

    /**
     * 传入签名头和url串访问浏览器
     * 显示标题栏，不显示加载框
     */
    public void openBrowserX5Activity(Context context, String title, String url, String referrer) {
        openBrowserX5Activity(context, title, url, referrer, null, true, false);
    }

    /**
     * 传入url串访问浏览器, 显示标题栏
     *
     * @param showPreLoad 是否显示加载框由
     */
    public void openBrowserX5Activity(Context context, String url, boolean showPreLoad) {
        openBrowserX5Activity(context, null, url, null, null, true, showPreLoad);
    }

    /**
     * 传入url串访问浏览器
     *
     * @param showTitle   是否显示标题栏，
     * @param showPreLoad 是否显示加载框由
     */
    public void openBrowserX5Activity(Context context, String url, boolean showTitle, boolean showPreLoad) {
        openBrowserX5Activity(context, null, url, null, null, showTitle, showPreLoad);
    }

    /**
     * 隐私政策浏览器
     */
    public void openPrivacyBrowserActivity(Context context, String title, String url) {
        Intent intent = new Intent(context, PrivacyBrowserActivity.class);
        intent.putExtra(MainConfig.INTENT_TITLE, title);
        intent.putExtra(MainConfig.INTENT_WEB_URL, url);
        IntentTool.startActivity(context, intent);
    }
}
